<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="com.pojo.OUser"%>
<%@ page import="com.pojo.Wtd"%>
<%@ page import="com.pojo.Statis"%>
<%@ page import="java.util.List"%>
<%@ page import="java.util.Map"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.text.*"%>
<%@ page import="java.math.BigDecimal"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd 

">
<%
	OUser user = (OUser) request.getAttribute("user");
	String id = request.getParameter("id");
	BigDecimal openprice = (BigDecimal) session.getAttribute("statisOpenprice");
	//Statis meiri = (Statis) request.getAttribute("meiri");
%>
<%
	List<Map> list = (List<Map>) request.getAttribute("list");
	Map mp = (Map) request.getAttribute("map");
	Statis zhidao = (Statis)mp.get("meiri");
	String sp = (String)mp.get("goods");
	String goods1 = (String)request.getAttribute("goods1");
%>
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>个人信息</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="Assets/css/reset.css" />
<script type="text/javascript" src="Assets/js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="Assets/js/js_z.js"></script>
<script
	src="<%=basePath%>bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
<script src="<%=basePath%>bower_components/jquery/dist/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="Assets/css/thems.css">
<script type="text/javascript" language="javascript">
	$(document).ready(function() {
		var id='<%=user.getUserID()%>';
		weituo(id);
		picture();	
		fun123();//页面加载下拉框的数据	
		getgoodnum();
		getmoneynum();
	});
</script>
<script type="text/javascript" language="javascript">
//获取用户个人的商品余量
function getgoodnum() {
		var goods = $("#select1").find("option:selected").text();
		var UserID = '<%=user.getUserID()%>';
		$.ajax({
			type : 'get',
			url : 'getgoodnum.html',
			data:{'goods':goods,'UserID':UserID},
			success : function(data) {
				var html="";
				$('#yuliang').html(data);
			}
		});
	}
	//获得用户资产
function getmoneynum() {
	var UserID = '<%=user.getUserID()%>';
	$.ajax({
		type : 'get',
		url : 'getmoneynum.html?UserID='+UserID,
		success : function(data) {
			var html="";
			$('#jfye').html(data);
		}
	});
}



//动态更改图片
function picture(){
	var uid ='<%=user.getUserID()%>';
	if (uid == 100000) {
		document.getElementById("typediv1").style.visibility = "visible";//显示			
	} else {
		document.getElementById("typediv1").style.visibility = "hidden";//隐藏
	}
	var goods = <%=sp%>;
	console.log(goods);
	if(goods=="宝石"){
		$("#pin-goods").src="<%=basePath%>Assets/images/aa.jpg"
	}
	else if(goods=="bb"){
		$("#pin-goods").src="<%=basePath%>Assets/images/aa.jpg"
	}
}

function fun123(){
	var goods = <%=sp%>
	//alert(goods);
    document.getElementById("select1").value = goods;
}

	function CheckForm() {
		if (document.myform.num.value == "") {
			alert("需要填写交易数量！");
			return false;
		}
		if (document.myform.jiage.value == "") {
			alert("需要填写挂售价格！");
			return false;
		}
		return true;
	}
	function setPrice(a, b) {

		if (b == 1) {
			//	alert(b)
			//	$("#r2").attr("checked", false);
			//	$("#r1").attr("checked", true);
			document.getElementById('r1').checked = true
			//	
		} else {
			//	alert(b)
			document.getElementById('r2').checked = true
		}
		$('#jiage').val(a)

	}
	function mai1(list1, list2) {
		var html = "";

		for (var i = 0; i < 5; i++) {
			if (list1.length > 0 && i < list1.length) {
				var m1 = list1[i]
				html += '<tr><td>买'
						+ (i + 1)
						+ '</td><td><a href="####" onclick="javascript:setPrice('
						+ m1.wprice + ',1) ;return false">' + m1.wprice
						+ '</a></td><td>' + m1.wcount + '</td>';
			} else
				html += '<tr><td>买' + (i + 1) + '</td><td>-</td><td>-</td>';

			if (list2.length > 0 && i < list2.length) {
				var m2 = list2[i]
				html += '<td>卖'
						+ (i + 1)
						+ '</td><td><a href="####" onclick="javascript:setPrice('
						+ m2.wprice + ',2) ;return false">' + m2.wprice
						+ '</a></td><td>' + m2.wcount + '</td></tr>';
			} else
				html += '<td>卖' + (i + 1) + '</td><td>-</td><td>-</td></tr>';
		}

		//}
		$('#table1').html(html);
	}
	function mai2(list3, list4) {
		var html = "";
		//alert(JSON.stringify(list4))
		for (var i = 4; i >= 0; i--) {
			if (list3.length > 0 && i < list3.length) {
				var m1 = list3[i]
				html += '<tr><td>买'
						+ (i + 1)
						+ '</td><td><a href="####" onclick="javascript:setPrice('
						+ m1.wprice + ',1) ;return false">' + m1.wprice
						+ '</a></td><td>' + m1.wcount + '</td>';
			} else
				html += '<tr><td>买' + (i + 1) + '</td><td>-</td><td>-</td>';

			if (list4.length > 0 && i < list4.length) {
				var m2 = list4[i]
				html += '<td>卖'
						+ (i + 1)
						+ '</td><td><a href="####" onclick="javascript:setPrice('
						+ m2.wprice + ',2) ;return false">' + m2.wprice
						+ '</a></td><td>' + m2.wcount + '</td></tr>';
			} else
				html += '<td>卖' + (i + 1) + '</td><td>-</td><td>-</td></tr>';
		}

		//}
		$('#table2').html(html);
	}
	funrefresh();
	function funrefresh(){
		fun2();
		weituo("<%=user.getUserID()%>");
	}
	window.setInterval("funrefresh()", 3000);
	function fun2() {
		var goods = $("#select1").find("option:selected").text();
		$.ajax({
			type : 'get',
			url : 'getprice.html?goods='+goods,
			success : function(data) {
				var id =<%=user.getUserID()%>;
				//console.log(data);
				var list = JSON.parse(data);
				if (id == 100000) {
					mai1(list[0], list[1]);
					mai2(list[2], list[3]);
				} else {
					mai1(list[0], list[1]);
				}

			}
		});
	}
	var flag = 1;
	function main() {
		if (flag == 0)
			return;

		var url = "insertwtd.html";
		//alert("当前系统正在紧急维护,请耐心等候,预计两小时调整好");
		//return;
		var d = {};

		if ($("#r1").is(":checked")) {
			d.ttype = $("#r1").val();
		}
		if ($("#r2").is(":checked")) {
			d.ttype = $("#r2").val();
		}
		if (!('ttype' in d)) {
			alert("请选择买卖方式");
			flag = 1;
			return;
		}
		var num = document.getElementById("num").value;
		var jiage = document.getElementById("jiage").value;
		if (jiage == '' || num == '') {
			alert("数量和价格不能为空");
			flag = 1;
			return;
		}

		/*调试价格在指导价的上下百分之十  2017/12/1  11:33 yy  */
		var openprice =<%=zhidao.getOpenprice()%>;
		if (jiage > openprice * 1.1) {
			alert("您的价格过高,请重新输入价格");
			flag = 1;
			return;
		}
		if (jiage < openprice * 0.9) {
			alert("您的价格过低,请重新输入价格");
			flag = 1;
			return;
		}

		var consume = jiage * num;
		//alert(d.ttype + "," + jiage + "," + num + "," + consume);
		d.wcount = num;
		d.wprice = jiage;
		d.consume = consume;
		d.goods = $("#select1").find("option:selected").text();
		flag = 0;
		$.ajax({
			type : 'post',
			url : url,
			data : d,
			success : function(data) {
				//console.log(data);
				var s1 = "今天是周末哦,请工作日内进行交易哦!";
				var s2 ="您委托单的价格不在指导价的上下百分之十，请重新输入价格！";
				var s3 = "您的余额不足以购买该订单，请先充值，或者降低挂买数量！";
				var s4 = "现在还不能提交委托单哦！";
				var s5 = "您提交的所有委托单的总金额大于您拥有的余额，请降低挂买数量!";
				var s6="您暂时还没有该商品，不能够进行买卖，请先购买该商品！";
				var s7 = "您的库存与您拥有的宝石数不符合,请尽快跟客户联系!";
				var s8 = "您冻结的数量为负，请尽快跟客户联系查询资产信息!";
				var s9 = "您的积分包数量不足，请先兑换，或者降低挂售数量！";
				var s10 = "您的委托单已提交成功";
				var s11="春假期间暂不交易，正月初八（2月23日）正常交易";
				if (data == "untradedate") {
					alert(s1);
				} else if (data == "priceerror") {
					alert(s2);
				}else if (data == "untradeyear") {
					alert(s11);
				}else if (data == "unencash") {
					alert(s3);
				} else if (data == "untrade") {
					alert(s4);
				}else if (data == "unfinish") {
					alert(s5);
				} else if (data == "nogoods") {
					alert(s6);
				}else if (data == "undangerous") {
					alert(s7);
				} else if (data == "djnumerror") {
					alert(s8);
				}else if (data == "unwcount") {
					alert(s9);
				} else{
					alert(s10);
				}
				flag = 1;
				qingkong();
				weituo("<%=user.getUserID()%>")
			},
			error : function(jqXHR, textStatus, errorThrown) {
				flag = 1;
			}
		});
	}
	function qingkong(){
		document.getElementById("num").value='';
		document.getElementById("jiage").value='';
	}
	function clearNoNum(obj){ 
	    obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符  
	    obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
	    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
	    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数  
	    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
	        obj.value= parseFloat(obj.value); 
	    } 
	} 
	function clearNoNum1(obj){ 
	    obj.value = obj.value.replace(/[^\d]/g,"");  //清除“数字”和“.”以外的字符  
	 //   obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的  
	    obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$","."); 
	    obj.value = obj.value.replace(/^(\-)*(\d+)\.().*$/,'$1$2.$3');//只能输入两个小数  
	    if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
	        obj.value= parseFloat(obj.value); 
	    } 
	} 
	/* 撤单 */
	var flag2 = 1;
	function cancle(id) {
		if (flag2 == 0)
			return;

		var w = {
			wid : ""
		};
		w.wid = id;
		flag2 = 0;
		$.ajax({
			type : 'post',
			url : 'canclewtd.html',
			data : w,
			success : function() {
				alert("您的这笔委托单已撤销，如有问题，请跟客服联系");
				flag2 = 1;
				weituo("<%=user.getUserID()%>")
			}
		});
	}

	//查看委托单
	function weituo(id) {
		var s1 = id;
		var info = {
			UserID : ""
		};
		info.UserID = s1;
		var str = JSON.stringify(info);
		$.ajax({
					type : 'post',
					url : 'selectwtd.html?UserID=' + s1,
					data : {
						"info" : str
					},
					scriptCharset : 'utf-8',
					success : function(data) {
						var subject = JSON.parse(data);
						//console.log(data)
						var html = "";
						for ( var i in subject) {
							html += '<tr><td>'
									+ subject[i].wtime
									+ '</td><td>'
									+ subject[i].wprice
									+ '</td><td>'
									+ subject[i].ttype
									+ '</td><td>'
									+ subject[i].wcount
									+ '</td><td>'
									+ subject[i].tcount
									+ '</td><td><input type="button" value="撤销" id="'
									+ subject[i].wid
									+ '" onclick="cancle(this.id )"></input></td></tr>';

						}

						$('#wtdmingxi').html(html);
					}
				});
		getgoodnum();
		getmoneynum();
	}

	function iFrameHeight() {
		var ifm = document.getElementById("iframecon");
		var subWeb = document.frames ? document.frames["iframepage"].document
				: ifm.contentDocument;
		if (ifm != null && subWeb != null) {
			ifm.height = subWeb.body.scrollHeight;
		}
	}
	window.setInterval("iFrameHeight()", 200);
	
	function goodsChange(){
		 //document.getElementById("select1").value = goods;
		 var goods=$("#select1").val();
		 window.location.href="selectwtdprice.html?goods="+goods
	}
</script>
</head>
<body>
	<%-- <%
		for (Object obj : list) {
			//response.write(obj.toString());
			//out.println(obj.toString());
			Wtd o = (Wtd) obj;
	%> --%>
	<div class="h_top">
		<div class="h_top_m">
			欢迎来到商品交易大厅网 <span> 欢迎回来会员<%=user.getUserID()%> <a
				href="logout.html">安全退出</a>
			</span>
		</div>
	</div>
	<!--顶部-->
	<!--头部-->
	<div class="header clearfix">
		<div class="logo">
			<a href="<%=basePath%>index.html"><img
				src="Assets/images/logo.png" alt="网" /></a>
		</div>
		<div class="tel">
			<!--img src="Assets/images/tel.png" alt="400-168-0000"-->
		</div>
	</div>
	<div class="nav_bg">
		<ul class="nav clearfix">
			<li><a href="main.html">首页</a></li>
			<li><a href="bypt.html">商品交易</a></li>
			<li class="now"><a href="member.html">我的账户</a></li>
		</ul>
	</div>

	<!--头部-->

	<div class="space_hx">&nbsp;</div>
	<div class="second clearfix">
		<div class="scd_l">
			<ul class="sidenav">

				<li><a href="member.html">个人信息</a></li>
				<li class="now"><a href="selectwtdprice.html?goods=宝石">商品挂单</a></li>
				<li><a href="selllist.html?page=1&last=5">售出记录</a></li>
				<li><a href="buylist.html?page=1&last=5">购买记录</a></li>
				<li><a href="gr_money.html?page=1&last=5">交易明细</a></li>
				<li><a href="tixian.html">提现明细</a></li>
				<li><a href="chongzhi.html">充值明细</a></li>
				<!-- <li><a href="tiqu.html">钱包管理</a></li> -->

			</ul>
			<div class="space_hx">&nbsp;</div>
		</div>

		<div class="scd_r">
			<div class="ucenter">
				<div class="box">
					<div class="box_h">
						<img src="Assets/images/icon10.png" alt="" /> <span class="red">购买挂单</span>
					</div>
				</div>

				<div class="">

					<table width="600">

						<tr>
							<td width="200">
							<%
							String pic = "Assets/images/aa.jpg";
							if(goods1.equals("帕帕拉宝石")){
								pic = "Assets/images/20180207110630.jpg";
								}
							%>
							<img id="pin-goods" src="<%=pic %>" height="200" width="200"> 
							<span style="font-size: 16pt; color: red">指导价格：<%=zhidao.getOpenprice()%></span>
							</td>
							<td><iframe src="<%=basePath%>jsp/echart/kxingtu2.html?goods=<%=goods1%>"
									marginheight="0" marginwidth="0" frameborder="0" scrolling="no"
									width="100%" height="100%" id="iframecon" name="iframepage"
									onLoad="iFrameHeight()"></iframe></td>
						</tr>

					</table>

				</div>

				<div class="box">
					<table>
						<thead>
							<tr>
								<th>类型</th>
								<th>价格</th>
								<th>数量</th>
								<th>类型</th>
								<th>价格</th>
								<th>数量</th>
							</tr>
						</thead>
						<tbody id="table1">

						</tbody>
					</table>
				</div>
				<div class="box" id="typediv1">
					<table>
						<thead>
							<tr>
								<th>类型</th>
								<th>价格</th>
								<th>数量</th>
								<th>类型</th>
								<th>价格</th>
								<th>数量</th>
							</tr>
						</thead>
						<tbody id="table2">

						</tbody>
					</table>
				</div>

				<form name="myform" action="?action=S" method="post"
					onSubmit="return CheckForm();">
					<table width="100%" border="0">
						<tr>
							<td>积分余额</td>
							<td id="jfye"></td>

						</tr>
						<tr>
							<td>商品余额</td>
							<td id="yuliang"></td>

						</tr>
						
						<tr>
							<td>选择商品</td>
							<td><select name="sp" id="select1" onchange="goodsChange()">
									<%
							for (int i =0;i<list.size();i++) {
								Map mmp = (Map)list.get(i);
								String selected = "";
								
								/* if (knowledgepoint.equals(ob.getType())) {
									selected = "selected='selected'";
								} */
						%>
						<option <%=selected%>><%=mmp.get("classname")%></option>
						<%
							}
						%> 
							</select></td>
						</tr>
						
						<tr>
							<td>交易方式</td>

							<td><input name="jylx" type="radio" id="r1" value="买">买</input>
								<input name="jylx" type="radio" id="r2" value="卖">卖</input></td>
						</tr>
						<tr>
							<td>意向价格</td>
							<td><input class="form-control" type="text" name="jiage"
								id="jiage" value="" onkeyup="clearNoNum()"></td>
						</tr>
						<tr>
							<td>买卖数额</td>
							<td><input class="form-control" type="text" name="num"
								id="num" onkeyup="clearNoNum1()"></td>
						</tr>

						<tr>
							<td></td>
							<td><input type="button" onclick="main()" value="委托" /> <input
								id="<%=user.getUserID()%>" type="button"
								onclick="weituo(this.id)" value="刷新明细" /></td>
						</tr>
					</table>
				</form>
				<table class="table table-striped table-bordered td-center"
					id="data-lists">
					<thead>
						<tr>
							<th>委托时间</th>
							<th>价格</th>
							<th>挂买/挂卖</th>
							<th>商品件数</th>
							<th>已成交件数</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="wtdmingxi">

					</tbody>
				</table>

			</div>
		</div>
		<div class="space_hx">&nbsp;</div>
		<div class="f_nav_bg">
			<dl class="f_nav clearfix">
				<dt>
					<img src="<%=basePath%>Assets/images/tel.png" />
				</dt>
				<dd>

					<div class="tip" style="float: left; width: 200px;">
						<span style="font-size: 16px;">商品团队</span>
						<li>太原金属企业站</li>
						<li>太原金属商城</li>
						<li>太原金属会员网</li>
					</div>

					<div class="tip" style="float: left; width: 200px;">
						<span style="font-size: 16px;">服务帮助</span>

						<li><a href="news.html?classid=4">为什么选择我们</a></li>

						<li><a href="news.html?classid=3">网站声明</a></li>

						<li><a href="news.html?classid=2">公司公告</a></li>

						<li><a href="news.html?classid=1">行业动态</a></li>

					</div>

					<div class="tip">
						<p>交易大厅</p>
						<p>&nbsp;</p>
					</div>
				</dd>
			</dl>
			<div class="copyriht">版权解释权归太原金属所有</div>
		</div>
</body>
<script>
	function AddEventInput() {
		//这里就不做兼容了  
		var value = document.getElementById('jiage').value;
		var reg = /(^[1-9]{1}[0-9]*$)|(^[0-9]*\.[0-9]{2}$)/
		if (!reg.test(value)) {
			alert("请输入大于0的整数或者保留两位小数");
			document.getElementById("jiage").value = '';
		}
	}
	function AddEventInput1() {
		//这里就不做兼容了  
		var value = document.getElementById('num').value;
		var reg = /(^[1-9]{1}[0-9]*$)/
		if (!reg.test(value)) {
			alert("请输入大于0的整数");
			document.getElementById("num").value = '';
		}
	}
</script>

</html>
